package com.hougong.im.pool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 记录当前正在和那个好友哪个群聊天
 */
public class ChatWithPool {
    private static final Logger LOGGER=LoggerFactory.getLogger(ChatWithPool.class);
    private ChatWithPool(){

    }
    // 用于存放正在和谁聊天
    private static ConcurrentHashMap<Long, Long> chatWithFriend = new ConcurrentHashMap<>();
    // 用于存放正在和哪个群聊天
    private static ConcurrentHashMap<Long,Long> chatWithGroup=new ConcurrentHashMap<>();
    /**************  好友  **************/
    public static boolean setWithFriend(Long currentUid,Long fid){
        Long put = chatWithFriend.put(currentUid, fid);
        if(put==null){
            LOGGER.info("用户 "+currentUid+" 打开面板和好友 "+fid+" 聊天");
        }else {
            LOGGER.warn("用户 "+currentUid+" 与之前的好友 "+put +" 聊天面板没关闭 又来进入新的好友面板了？");
        }
        return true;
    }
    public static boolean removeWithFriend(Long currentUid,Long fid){
        Long remove = chatWithFriend.remove(currentUid);
        LOGGER.info("用户 "+currentUid+"关闭好友聊天面板");
        return true;
    }

    public static Long  queryWithFriend(Long currentUid){
        Long fid = chatWithFriend.get(currentUid);
        return fid;
    }
    /************  群  *************/
    public static boolean setWithGroup(Long currentUid,Long gid){
        Long put = chatWithGroup.put(currentUid, gid);
        if(put==null){
            LOGGER.info("用户 "+currentUid+" 打开面板和群 "+gid+" 聊天");
        }else {
            LOGGER.error("用户 "+currentUid+" 与之前的群 "+put +" 聊天面板没关闭 又来进入新的群面板了？");
        }
        return true;
    }
    public static boolean removeWithGroup(Long currentUid,Long gid){
        Long remove = chatWithGroup.remove(currentUid);
        LOGGER.info("用户 "+currentUid+"关闭群聊天面板");
        return true;
    }

    public static Long  queryWithGroup(Long currentUid){
        Long gid = chatWithGroup.get(currentUid);
        return gid;
    }
}
